<<<<<<< HEAD
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <meta content="no-cache" http-equiv="Cache-Control">
    <title>源之东方</title>
    <link href="__STATIC__/css/shopCar.css" rel="stylesheet"/>
</head>
<div class="nav footer fixed-bar" data-trackid="全站-底部导航">
    <a href="/" data-trackid="全站-底部导航-首页">首页</a>
    <a href="/category.html" data-trackid="全站-底部导航-分类">分类</a>
    <a href="/cart.html" class="on" data-trackid="全站-底部导航-购物车">购物车</a>
    <a href="/myself.html" data-trackid="全站-底部导航-我">我的</a>
</div><!-- //底部导航结束 -->
<body>
<div class="header">
    <div class="left"><a href="javascript:;" class="a-back"><span>返回</span></a></div>
    <div class="center">
        <h1>购物车</h1>
    </div>
</div><!--//头部结束-->

<div class="content">
    <div class="cart-main">
        <!--list-->
        <div class="cart-list">
            <div class="cart-shop">
                <div class="cart-title">购物车详情</div>
                <div class="cart-edit"><a href="javascript:;" class="btn btn-default cartEdit">编辑</a></div>
            </div>
            <div class="cart-box">
                <!--/商品开始-->
                {volist name="product_list" id='vo'}
                <div {if condition="$vo.select == 1"} class="cart-group checked" {else /} class="cart-group" {/if} data-id="{$vo.id}">
                    <div class="cart-icb"><input type="checkbox" name="shop" class="icon-checkbox setSelectAll" {if condition="$vo.select == 1"} checked data-status="1" {else /} data-status="0" {/if}></div>
                    <div class="cart-item">
                        <div class="small">
                            <div class="p">
                                <a href="">
                                    <div class="ware-img ui-imglazyload" data-url="http://img.58bjcf.com/{$vo.url}"></div>
                                </a>
                            </div>
                            <div class="d">
                                <a href="#"><h3 class="d-title clamp">{$vo.description}</h3></a>
                                <div class="d-main" id="sub_price_{$vo.id}">
                                    <div class="sub">
                                        <p class="quantity">{$vo.name} <i>x</i><span>{$vo.num}</span></p>
                                        <span class="price">
                                            <span class="s">￥<em class="n">{$vo.member_price}</em>(会员价)</span><span style="margin: 0 .5rem;font-size: 1.2rem;color: #999;">￥<span class="no_member">{$vo.price}</span>(市场价)</span>
										</span>
                                    </div>
                                    <div class="opt">
                                        <div class="number" data-id="{$vo.id}">
                                            <button type="button" class="decrease">-</button>
                                            <input type="number" class="num" min="1" max="{$vo.stock}" name="quantity" value="{$vo.num}">
                                            <button type="button" class="increase">+</button>
                                        </div>
                                        <i class="icon-del"></i>
                                    </div>
                                </div>
                            </div>
                        </div><!-- //单品结束 -->
                    </div>
                </div>
                {/volist}
                <!-- /商品结束 -->
            </div>
            <div class="cart-group cart-footer" id="cart_footer">
                <div class="cart-icb">
                    <input type="checkbox" name="shop" class="icon-checkbox selectAll" {if condition="$checked_all == 1"} checked data-check="1"  {else /} data-checked="0" {/if}></div>
                <div class="cart-item">
                    <a href="/payment.html" {if condition="$pay == 1"} class="btn btn-pay" {else /}  class="btn btn-pay disabled" {/if} url="payment.html">结算</a>
                    <div class="total">总计：<b>￥{$count_price}</b></div>
                    <div class="quantity">共<b>{$all_num}</b>件商品</div>
                </div>
            </div>
        </div>

    </div>
</div>
<script src="__STATIC__/js/zepto.min.js"></script>
<script src="__STATIC__/js/base.min.js"></script>
<script src="__STATIC__/js/shopin.js"></script>
<!--<script src="__STATIC__/js/cart.js"></script>-->
<script>
    ;(function(){
        //编辑
        $(".cart-main").find('.cart-list').each(function() {
            var obj = $(this);
            obj.find('.cartEdit').click(function() {
                if(!$(this).hasClass('active')){
                    $(this).addClass('active').text('确定');
                    obj.addClass('editOrder');
//                    var id = $('.')
                }else{
                    $(this).removeClass('active').text('编辑');
                    obj.removeClass('editOrder');
                }
            });

            //全选
            obj.find('.selectAll').on('change', 'input', function() {
                var that = $(this);
                var check = parseInt(that.attr('data-check'));
                $.ajax({
                    type : 'post',
                    url : '/changeAll',
                    data : {type : check},
                    success : function (data) {
                        console.log(data);
                        if(data.status == 1) {
                            (check == 1) ? that.attr('data-check', 0) : that.attr('data-check', 1);
                        }
                    },
                    error : function (e) {
                        console.log(e);
                    }
                });
                var ssa = obj.find('.setSelectAll');
                var value = this.checked;
                if(value == true) {
                    for(var i = 0; i < ssa.length; i++) {
                        ssa[i].checked = true;
                        ssa.parent().parent().addClass('checked');
                    }
                }else{
                    for(var i = 0; i < ssa.length; i++){
                        ssa[i].checked = false;
                        ssa.parent().parent().removeClass('checked');
                    }
                }
                setButton();
                setTotal();
            });

            // 选中/未选中
            obj.find('.setSelectAll').on('change', 'input', function() {
                var id = $(this).parent().parent().attr('data-id');
                var that = $(this);
                var status = $(this).attr('data-status');
                $.ajax({
                    url : '/changSelect',
                    type : 'post',
                    data : {
                        id : id,
                        status : status
                    },
                    success : function (data) {
                        if(data.status == 1) {
                            if(parseInt(status) == 1) {
                                that.parent().parent().removeClass('checked');
                                that.attr('data-status', 0);
                            } else {
                                that.parent().parent().addClass('checked');
                                that.attr('data-status', 1);
                            }

                            var ssa = obj.find('.setSelectAll');
                            var count = ssa.length;
                            var selectCount = 0;
                            var value = this.checked;
                            for(var i = 0; i < count; i++) {
                                if(ssa[i].checked == true){
                                    selectCount++;
                                }
                            }
                            if(value == true) {
                                $(this).parent().parent().addClass('checked');
                            }else{
                                $(this).parent().parent().removeClass('checked');
                            }
                            if(count == selectCount) {
                                obj.find('.selectAll').prop('checked', true);
                            }else{
                                obj.find('.selectAll').prop('checked', false);
                            }
                            setButton();
                            setTotal();
                        }
                    },
                    error : function (e) {

                    }
                });
            });

            //删除
            obj.find('.icon-del').click(function() {
                var that = $(this);
                var id = that.parent().find('div').attr('data-id');
                $.ajax({
                    url : '/delProduct',
                    type : 'post',
                    data : {
                        id : id
                    },
                    success : function (data) {
                        console.log(data);
                        if(data.status == 1) {
                            var len = obj.find('.cart-box .cart-group').length;
                            if( len <= 1){
                                $(this).closest(".cart-list").remove();
                            }else{
                                $(this).closest(".cart-group").remove();
                            }
                            setTotal();
                        } else {
                            alert(data.message);
                        }
                    },
                    error : function (e) {

                    }
                });
                var len = obj.find('.cart-box .cart-group').length;
                if( len <= 1){
                    $(this).closest(".cart-list").remove();
                }else{
                    $(this).closest(".cart-group").remove();
                }
                setTotal();
            });

            //调整购买数量 新增
            obj.find(".increase").click(function() {
                var that = $(this);
                var n = that.parent().find('.num');
                var id = that.parent().attr('data-id');
                $.ajax({
                    url : '/addOrReduce',
                    type : 'post',
                    data : {
                        type : 'add',
                        id : id
                    },
                    success : function (data) {
                        if(data.status == 1) {
                            n.val(parseInt(n.val()) + 1);
                            $('#sub_price_' + id + ' p[class="quantity"] span').text(n.val());
                            $('#sub_price div p[class="quantity"] span').text(parseInt(n.val()));
                            setTotal();
                        } else {
                            alert(data.message);
                        }
                    },
                    error : function (e) {

                    }
                });
                // ajax代码可以放这里传递到数据库实时改变总价
            });
            // 减少数量
            obj.find(".decrease").click(function() {
                var that = $(this);
                var n = that.parent().find('.num');
                var id = that.parent().attr('data-id');
                $.ajax({
                    url : '/addOrReduce',
                    type : 'post',
                    data : {
                        type : 'reduce',
                        id : id
                    },
                    success : function (data) {
                        if(data.status == 1) {
                            n.val(parseInt(n.val()) - 1);
                            $('#sub_price_' + id + ' p[class="quantity"] span').text(n.val());
                            $('#sub_price div p[class="quantity"] span').text(parseInt(n.val()));
                            setTotal();
                        } else {
                            alert(data.message);
                        }
                    },
                    error : function (e) {

                    }
                });
            });
            obj.find('.num').blur(function(){
                setTotal();
            });

            //设置结算按钮的状态
            function setButton (){
                if(obj.find(".setSelectAll:checked").length > 0){
                    obj.find('.btn-pay').removeClass('disabled');
                }else{
                    obj.find('.btn-pay').addClass('disabled');
                }
            }

            function setTotal() {
                var quantity = 0;	//总数量
                var total = 0;		//总价格
                var len = obj.find('.checked').length;
                if(len <= 1){
                    obj.find(".total b").html('￥0.00');
                    obj.closest('.cart-list').find(".quantity b").html(0);
                }
                obj.find('.cart-box .checked').each(function(i){
                    var number = $(this).find('.num').val();		//数量
                    if("{:session('Auth.IsVIP')}") {
                        var price = $(this).find('.price .n').text();	//单价
                    } else {
                        var price = $(this).find('.price .no_member').text();	//单价
                    }
                    total += parseInt(number) * parseFloat(price) * 100;
                    quantity += parseInt(number);
                    obj.find(".total b").html('￥' + (total/100).toFixed(2));
                    obj.find(".quantity b").html(quantity);
                    if(quantity >= 1){
                        obj.find('.btn-pay').removeClass('disabled');
                    }else{
                        obj.find('.btn-pay').addClass('disabled');
                    }
                });
            }
        });
    })();

</script>
</body>
=======
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <meta content="no-cache" http-equiv="Cache-Control">
    <title>源之东方</title>
    <link href="__STATIC__/css/shopCar.css" rel="stylesheet"/>
</head>
<div class="nav footer fixed-bar" data-trackid="全站-底部导航">
    <a href="/" data-trackid="全站-底部导航-首页">首页</a>
    <a href="/category.html" data-trackid="全站-底部导航-分类">分类</a>
    <a href="/cart.html" class="on" data-trackid="全站-底部导航-购物车">购物车</a>
    <a href="/myself.html" data-trackid="全站-底部导航-我">我的</a>
</div><!-- //底部导航结束 -->
<body>
<div class="header">
    <div class="left"><a href="javascript:;" class="a-back"><span>返回</span></a></div>
    <div class="center">
        <h1>购物车</h1>
    </div>
</div><!--//头部结束-->

<div class="content">
    <div class="cart-main">
        <!--list-->
        <div class="cart-list">
            <div class="cart-shop">
                <div class="cart-title">购物车详情</div>
                <div class="cart-edit"><a href="javascript:;" class="btn btn-default cartEdit">编辑</a></div>
            </div>
            <div class="cart-box">
                <!--/商品开始-->
                {volist name="product_list" id='vo'}
                <div {if condition="$vo.select == 1"} class="cart-group checked" {else /} class="cart-group" {/if} data-id="{$vo.id}">
                    <div class="cart-icb"><input type="checkbox" name="shop" class="icon-checkbox setSelectAll" {if condition="$vo.select == 1"} checked data-status="1" {else /} data-status="0" {/if}></div>
                    <div class="cart-item">
                        <div class="small">
                            <div class="p">
                                <a href="">
                                    <div class="ware-img ui-imglazyload" data-url="http://img.58bjcf.com/{$vo.url}"></div>
                                </a>
                            </div>
                            <div class="d">
                                <a href="#"><h3 class="d-title clamp">{$vo.description}</h3></a>
                                <div class="d-main" id="sub_price_{$vo.id}">
                                    <div class="sub">
                                        <p class="quantity">{$vo.name} <i>x</i><span>{$vo.num}</span></p>
                                        <span class="price">
                                            <span class="s">￥<em class="n">{$vo.member_price}</em>(会员价)</span><span style="margin: 0 .5rem;font-size: 1.2rem;color: #999;">￥<span class="no_member">{$vo.price}</span>(市场价)</span>
										</span>
                                    </div>
                                    <div class="opt">
                                        <div class="number" data-id="{$vo.id}">
                                            <button type="button" class="decrease">-</button>
                                            <input type="number" class="num" min="1" max="{$vo.stock}" name="quantity" value="{$vo.num}">
                                            <button type="button" class="increase">+</button>
                                        </div>
                                        <i class="icon-del"></i>
                                    </div>
                                </div>
                            </div>
                        </div><!-- //单品结束 -->
                    </div>
                </div>
                {/volist}
                <!-- /商品结束 -->
            </div>
            <div class="cart-group cart-footer" id="cart_footer">
                <div class="cart-icb">
                    <input type="checkbox" name="shop" class="icon-checkbox selectAll" {if condition="$checked_all == 1"} checked data-check="1"  {else /} data-checked="0" {/if}></div>
                <div class="cart-item">
                    <a href="/payment.html" {if condition="$pay == 1"} class="btn btn-pay" {else /}  class="btn btn-pay disabled" {/if} url="payment.html">结算</a>
                    <div class="total">总计：<b>￥{$count_price}</b></div>
                    <div class="quantity">共<b>{$all_num}</b>件商品</div>
                </div>
            </div>
        </div>

    </div>
</div>
<script src="__STATIC__/js/zepto.min.js"></script>
<script src="__STATIC__/js/base.min.js"></script>
<script src="__STATIC__/js/shopin.js"></script>
<!--<script src="__STATIC__/js/cart.js"></script>-->
<script>
    ;(function(){
        //编辑
        $(".cart-main").find('.cart-list').each(function() {
            var obj = $(this);
            obj.find('.cartEdit').click(function() {
                if(!$(this).hasClass('active')){
                    $(this).addClass('active').text('确定');
                    obj.addClass('editOrder');
//                    var id = $('.')
                }else{
                    $(this).removeClass('active').text('编辑');
                    obj.removeClass('editOrder');
                }
            });

            //全选
            obj.find('.selectAll').on('change', 'input', function() {
                var that = $(this);
                var check = parseInt(that.attr('data-check'));
                $.ajax({
                    type : 'post',
                    url : '/changeAll',
                    data : {type : check},
                    success : function (data) {
                        console.log(data);
                        if(data.status == 1) {
                            (check == 1) ? that.attr('data-check', 0) : that.attr('data-check', 1);
                        }
                    },
                    error : function (e) {
                        console.log(e);
                    }
                });
                var ssa = obj.find('.setSelectAll');
                var value = this.checked;
                if(value == true) {
                    for(var i = 0; i < ssa.length; i++) {
                        ssa[i].checked = true;
                        ssa.parent().parent().addClass('checked');
                    }
                }else{
                    for(var i = 0; i < ssa.length; i++){
                        ssa[i].checked = false;
                        ssa.parent().parent().removeClass('checked');
                    }
                }
                setButton();
                setTotal();
            });

            // 选中/未选中
            obj.find('.setSelectAll').on('change', 'input', function() {
                var id = $(this).parent().parent().attr('data-id');
                var that = $(this);
                var status = $(this).attr('data-status');
                $.ajax({
                    url : '/changSelect',
                    type : 'post',
                    data : {
                        id : id,
                        status : status
                    },
                    success : function (data) {
                        if(data.status == 1) {
                            if(parseInt(status) == 1) {
                                that.parent().parent().removeClass('checked');
                                that.attr('data-status', 0);
                            } else {
                                that.parent().parent().addClass('checked');
                                that.attr('data-status', 1);
                            }

                            var ssa = obj.find('.setSelectAll');
                            var count = ssa.length;
                            var selectCount = 0;
                            var value = this.checked;
                            for(var i = 0; i < count; i++) {
                                if(ssa[i].checked == true){
                                    selectCount++;
                                }
                            }
                            if(value == true) {
                                $(this).parent().parent().addClass('checked');
                            }else{
                                $(this).parent().parent().removeClass('checked');
                            }
                            if(count == selectCount) {
                                obj.find('.selectAll').prop('checked', true);
                            }else{
                                obj.find('.selectAll').prop('checked', false);
                            }
                            setButton();
                            setTotal();
                        }
                    },
                    error : function (e) {

                    }
                });
            });

            //删除
            obj.find('.icon-del').click(function() {
                var that = $(this);
                var id = that.parent().find('div').attr('data-id');
                $.ajax({
                    url : '/delProduct',
                    type : 'post',
                    data : {
                        id : id
                    },
                    success : function (data) {
                        console.log(data);
                        if(data.status == 1) {
                            var len = obj.find('.cart-box .cart-group').length;
                            if( len <= 1){
                                $(this).closest(".cart-list").remove();
                            }else{
                                $(this).closest(".cart-group").remove();
                            }
                            setTotal();
                        } else {
                            alert(data.message);
                        }
                    },
                    error : function (e) {

                    }
                });
                var len = obj.find('.cart-box .cart-group').length;
                if( len <= 1){
                    $(this).closest(".cart-list").remove();
                }else{
                    $(this).closest(".cart-group").remove();
                }
                setTotal();
            });

            //调整购买数量 新增
            obj.find(".increase").click(function() {
                var that = $(this);
                var n = that.parent().find('.num');
                var id = that.parent().attr('data-id');
                $.ajax({
                    url : '/addOrReduce',
                    type : 'post',
                    data : {
                        type : 'add',
                        id : id
                    },
                    success : function (data) {
                        if(data.status == 1) {
                            n.val(parseInt(n.val()) + 1);
                            $('#sub_price_' + id + ' p[class="quantity"] span').text(n.val());
                            $('#sub_price div p[class="quantity"] span').text(parseInt(n.val()));
                            setTotal();
                        } else {
                            alert(data.message);
                        }
                    },
                    error : function (e) {

                    }
                });
                // ajax代码可以放这里传递到数据库实时改变总价
            });
            // 减少数量
            obj.find(".decrease").click(function() {
                var that = $(this);
                var n = that.parent().find('.num');
                var id = that.parent().attr('data-id');
                $.ajax({
                    url : '/addOrReduce',
                    type : 'post',
                    data : {
                        type : 'reduce',
                        id : id
                    },
                    success : function (data) {
                        if(data.status == 1) {
                            n.val(parseInt(n.val()) - 1);
                            $('#sub_price_' + id + ' p[class="quantity"] span').text(n.val());
                            $('#sub_price div p[class="quantity"] span').text(parseInt(n.val()));
                            setTotal();
                        } else {
                            alert(data.message);
                        }
                    },
                    error : function (e) {

                    }
                });
            });
            obj.find('.num').blur(function(){
                setTotal();
            });

            //设置结算按钮的状态
            function setButton (){
                if(obj.find(".setSelectAll:checked").length > 0){
                    obj.find('.btn-pay').removeClass('disabled');
                }else{
                    obj.find('.btn-pay').addClass('disabled');
                }
            }

            function setTotal() {
                var quantity = 0;	//总数量
                var total = 0;		//总价格
                var len = obj.find('.checked').length;
                if(len <= 1){
                    obj.find(".total b").html('￥0.00');
                    obj.closest('.cart-list').find(".quantity b").html(0);
                }
                obj.find('.cart-box .checked').each(function(i){
                    var number = $(this).find('.num').val();		//数量
                    if("{:session('Auth.IsVIP')}") {
                        var price = $(this).find('.price .n').text();	//单价
                    } else {
                        var price = $(this).find('.price .no_member').text();	//单价
                    }
                    total += parseInt(number) * parseFloat(price) * 100;
                    quantity += parseInt(number);
                    obj.find(".total b").html('￥' + (total/100).toFixed(2));
                    obj.find(".quantity b").html(quantity);
                    if(quantity >= 1){
                        obj.find('.btn-pay').removeClass('disabled');
                    }else{
                        obj.find('.btn-pay').addClass('disabled');
                    }
                });
            }
        });
    })();

</script>
</body>
>>>>>>> 93c40d8086b7a8d5a9aa3548fdc8eb06a4272cf7
</html>